package com.atguigu.tingshu.order.mapper;

import com.atguigu.tingshu.model.order.OrderInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {


    @Select("select count(order_info.id) > 0\n" +
            "from order_info\n" +
            "         inner join order_detail\n" +
            "                    on order_info.id = order_detail.order_id\n" +
            "where user_id = #{userId}\n" +
            "  and item_type = #{itemType}\n" +
            "  and order_detail.item_id = #{itemId}\n" +
            "  and order_info.is_deleted = 0" +
            "  and order_status = '0901'")
    Boolean checkAlbumOrVipIsPaying(@Param("userId") Long userId, @Param("itemId") Long itemId, @Param("itemType") String itemType);


    @Select(" SELECT \n" +
            " order_detail.item_id\n" +
            " FROM `order_info`\n" +
            " INNER JOIN order_detail\n" +
            " ON order_info.id=order_detail.order_id\n" +
            " WHERE  order_info.user_id=#{userId}\n" +
            " AND order_info.item_type=#{itemType}\n" +
            " AND order_info.order_status='0901'")
    List<Long> checkTrackTypeItemPadding(@Param("itemType") String itemType, @Param("userId") Long userId);


    int updateOrderStatusSuccess(@Param("orderNo") String orderNo);

    void cancelOrder(String content);
}
